import pytest
from selenium import webdriver
import os

from selenium.webdriver.common.by import By


#pytest方法
@pytest.fixture(scope='session')
def driver():
    #初始化浏览器
    driver = webdriver.Firefox()
    #网址首页设置
    driver.get(os.getenv("url"))
    #窗口最大化
    driver.maximize_window()
    #返回driver数据
    yield driver
    #退出浏览器
    driver.quit()

    #账号输入
    driver.find_element(By.ID, 'username').send_keys('admin')
    #密码输入
    driver.find_element(By.ID, 'password').send_keys('123456')
    #登录按钮
    driver.find_element(By.CSS_SELECTOR, 'btn.btn-primary').click()


@pytest.fixture(scope='session')
def web_type():
    driver = None
    print('看看浏览器', os.getenv('webtype'))

    if 'chrome' == os.getenv('webtype'):
        driver = webdriver.Chrome()

    elif 'firefox' == os.getenv('webtype'):
        driver = webdriver.Firefox()

    driver.maximize_window()
    driver.implicitly_wait(10)

    yield driver

    driver.quit()
